package com.itHsuSE.demo5;

/**
 * @author Hsu琛君珩
 * @version 1.0
 */
public class Test7 {
    public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
        int[][] dp=new int[obstacleGrid.length][obstacleGrid[0].length];
        for(int i=0;i<obstacleGrid.length;i++){
            if(obstacleGrid[i][0]==1)continue;
            dp[i][0]=1;
        }
        for(int j=0;j<obstacleGrid[0].length;j++){
            if(obstacleGrid[0][j]==1)continue;
            dp[0][j]=1;
        }
        for(int i=1;i<obstacleGrid.length;i++){
            for(int j=1;j<obstacleGrid[0].length;j++){
                if(obstacleGrid[i][j]==1)continue;
                if(obstacleGrid[i-1][j]==1){
                    dp[i][j]=dp[i][j-1];
                }else if(obstacleGrid[i][j-1]==1){
                    dp[i][j]=dp[i-1][j];
                }else{
                    dp[i][j]=dp[i-1][j]+dp[i][j-1];
                }
            }
        }
        return dp[obstacleGrid.length-1][obstacleGrid[0].length-1];
    }

    public static void main(String[] args) {
/*        int[][] obstacleGrid={
                {0,0,0},
                {0,1,0},
                {0,0,0}
        };
*/
        int[][] obstacleGrid={
                {1,0}
        };
        uniquePathsWithObstacles(obstacleGrid);
    }

}


